#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

//int main()
//{
  //chdir("/home/lzs/linux");
  //FILE *fp = fopen("test.txt", "w");
  //pid_t ppid = getppid();
  //pid_t id = getpid();
  //while(1)
  //{
  //  printf("I am a process, pid: %d, 我的父进程id：%d\n", id, ppid);
  //  sleep(1);
  // }
  
//  return 0;
//}
const int num = 10;
int main()
{
  int i;
  for(i = 0; i < num; i++)
  {
    pid_t id = fork();
    if(id == 0)
    {
      //child
      while(1)
      {
        printf("我是子进程，pid：%d, ppid: %d\n", getpid(), getppid());
        sleep(1);
      }
    }
    else{
      //father:什么都不做
      printf("子进程被创建，pid：%d\n", id);
    }
    sleep(1);
  }

  while(1)
  {
    printf("我是子进程，pid：%d, ppid: %d\n", getpid(), getppid());
    sleep(1);
  }

  return 0;
}
